<html>
<head>
    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet" href="${ctx}/bootstrap/3.3.7/css/bootstrap.min.css" crossorigin="anonymous"/>
    <link href="${ctx}/font-awesome/3.0.0/css/font-awesome.min.css" rel="stylesheet"/>
    <link rel="stylesheet" href="${ctx}/css/index.css">
    <link rel="stylesheet" href="${ctx}/qiniu/main.css">
    <link rel="stylesheet" href="${ctx}/qiniu/highlight.css">
    <script src="${ctx}/jquery/2.1.4/jquery.min.js"></script>
    <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
    <script
            src="${ctx}/bootstrap/3.3.7/js/bootstrap.min.js"
            integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"
            crossorigin="anonymous"></script>
    <script src="${ctx}/js/iw.js"></script>
    <link rel="stylesheet" href="${ctx}/qiniu/highlight.css">

</head>
<body class="container-fuild" style="padding-top: 8px;">
<form class="form-horizontal" id="form">

    <div class="col-xs-6">
        <div class="form-group">
            <label for="title" class="col-sm-3 control-label">应用名称</label>
            <div class="col-sm-9">
                <input type="text" class="form-control" id="appId" name="appId" value="xianyu">
            </div>
        </div>
    </div>
    <input type="text" id="id" name="id" style="display: none" value="<#if app??>${app.id!''}</#if>"/>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="size" class="col-sm-3 control-label">应用渠道</label>
            <div class="col-sm-9">
                <select class="form-control" id="appStore" name="appStore">
                    <option value="">请选择应用市场</option>
                    <#list appStores as appStore>
                        <option value="${appStore.code}"
                                <#if app?? && app.appStore == appStore.code>selected</#if>><#if appStore.name??>${appStore.name}<#else>${appStore.code}</#if></option>
                    </#list >
                </select>
            </div>
        </div>
    </div>

    <div class="col-xs-6">
        <div class="form-group">
            <label for="title" class="col-sm-3 control-label">更新标题</label>
            <div class="col-sm-9">
                <input type="text" class="form-control" id="title" name="title"
                       value="<#if app??>${app.title}<#else>检测到新版本</#if>"/>
            </div>
        </div>
    </div>

    <div class="col-xs-6">
        <div class="form-group">
            <label for="title" class="col-sm-3 control-label">副标题</label>
            <div class="col-sm-9">
                <input type="text" class="form-control" id="subtitle" name="subtitle"
                       value="<#if app??>${app.subtitle}<#else>BUG修复</#if>"/>
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="title" class="col-sm-3 control-label">更新内容</label>
            <div class="col-sm-9">
                <input type="text" class="form-control" id="content" name="content"
                       value="<#if app??>${app.content}<#else>BUG修复</#if>"/>
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="title" class="col-sm-3 control-label">外网版本</label>
            <div class="col-sm-9">
                <input type="text" class="form-control" id="version" name="version"
                       value="<#if app??>${app.version}</#if>"/>
            </div>
        </div>
    </div>

    <div class="col-xs-6">
        <div class="form-group">
            <label for="title" class="col-sm-3 control-label">内部版本号</label>
            <div class="col-sm-9">
                <input type="text" class="form-control" id="innerCode" name="innerCode"
                       value="<#if app??>${app.innerCode}</#if>"/>
            </div>
        </div>
    </div>


    <div class="col-xs-6">
        <div class="form-group">
            <label for="size" class="col-sm-3 control-label">版本管理</label>
            <div class="col-sm-9">
                <select class="form-control" id="appMode" name="appMode">
                    <option value="">请选择版本模式</option>
                    <#list modes as mode>
                        <option value="${mode}"
                                <#if app?? && app.appMode == mode>selected<#else><#if mode=='Debug'>selected</#if></#if>>${mode.title}</option>
                    </#list>
                </select>
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="size" class="col-sm-3 control-label">提示升级</label>
            <div class="col-sm-9">
                <select class="form-control" id="tipUser" name="tipUser">
                    <option value="">是否提示升级</option>
                    <#list boolean as bl>
                        <option value="${bl}"
                                <#if app?? && app.tipUser == bl>selected<#else><#if bl=='False'>selected</#if></#if>>${bl.title}</option>
                    </#list>
                </select>
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="size" class="col-sm-3 control-label">强制升级</label>
            <div class="col-sm-9">
                <select class="form-control" id="forceUpdate" name="forceUpdate">
                    <option value="">是否提示强制更新</option>
                    <#list boolean as bl>
                        <option value="${bl}"
                                <#if app?? && app.forceUpdate == bl>selected<#else><#if bl=='False'>selected</#if></#if> >${bl.title}</option>
                    </#list>
                </select>
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="size" class="col-sm-3 control-label">同版本更新</label>
            <div class="col-sm-9">
                <select class="form-control" id="sameVersionUpdate" name="sameVersionUpdate">
                    <option value="">是否提示更新</option>
                    <#list boolean as bl>
                        <option value="${bl}"
                                <#if app?? && app.sameVersionUpdate == bl>selected<#else><#if bl=='False'>selected</#if></#if>>${bl.title}</option>
                    </#list>
                </select>
            </div>
        </div>
    </div>

    <div class="col-xs-6">
        <div class="form-group">
            <label for="size" class="col-sm-3 control-label">下载地址</label>
            <div class="col-sm-9">
                <input type="text" class="form-control" id="href" name="href" value="<#if app??>${app.href}</#if>"/>
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="size" class="col-sm-3 control-label">是否开启违禁包检测</label>
            <div class="col-sm-9">
                <select class="form-control" id="openBlackPkg" name="openBlackPkg">
                    <option value="">是否开启违禁包检测</option>
                    <option value="1" <#if app?? && app.openBlackPkg?? && app.openBlackPkg == 1>selected</#if>>是</option>
                    <option value="0" <#if app?? && app.openBlackPkg?? && app.openBlackPkg == 0>selected</#if>>否</option>
                </select>
            </div>
        </div>
    </div>
    <#if  upToken??>
        <div class="container" style="padding-top: 260px;">
            <div class="tab-content">
                <div role="tabpanel" class="tab-pane fade in active" id="demo" aria-labelledby="demo-tab">
                    <div class="row" style="margin-top: 20px;">
                        <input type="hidden" id="domain" value="http://p5vcsyy4d.bkt.clouddn.com/">
                        <input type="hidden" id="uptoken_url" value="${upToken}">
                        <div class="col-md-12">
                            <div id="container" style="position: relative;">
                                <a class="btn btn-default btn-lg " id="pickfiles" href="http://jssdk.demo.qiniu.io/#"
                                   style="position: relative; z-index: 1;">
                                    <i class="glyphicon glyphicon-plus"></i>
                                    <span>选择文件</span>
                                </a>
                                <div id="html5_1aj3rtennnga1n5h927gjn8343_container" class="moxie-shim moxie-shim-html5"
                                     style="position: absolute; top: 0px; left: 0px; width: 171px; height: 46px; overflow: hidden; z-index: 0;">
                                    <input id="html5_1aj3rtennnga1n5h927gjn8343" type="file"
                                           style="font-size: 999px; opacity: 0; position: absolute; top: 0px; left: 0px; width: 100%; height: 100%;"
                                           multiple="" accept=""></div>
                            </div>
                        </div>
                        <div style="display:none" id="success" class="col-md-12">
                            <div class="alert-success">
                                队列全部文件处理完毕
                            </div>
                        </div>
                        <div class="col-md-12 ">
                            <table class="table table-striped table-hover text-left"
                                   style="margin-top:40px;display:none">
                                <thead>
                                <tr>
                                    <th class="col-md-4">Filename</th>
                                    <th class="col-md-2">Size</th>
                                    <th class="col-md-6">Detail</th>
                                </tr>
                                </thead>
                                <tbody id="fsUploadProgress">
                                </tbody>
                            </table>
                        </div>
                    </div>

                </div>
                <div role="tabpanel" class="tab-pane fade" id="code" aria-labelledby="code-tab">

                    <div class="row" style="margin-top: 20px;">
                        <div class="col-md-12">
                        <pre><code class="javascript">
                        <span class="comment">//引入Plupload 、qiniu.js后</span>
                        <span class="keyword">var</span> uploader = Qiniu.uploader({
                            runtimes: <span class="string">'html5,flash,html4'</span>,    <span class="comment">//上传模式,依次退化</span>
                            browse_button: <span class="string">'pickfiles'</span>,       <span class="comment">//上传选择的点选按钮，**必需**</span>
                            uptoken_url: <span class="string">'/token'</span>,            <span class="comment">//Ajax请求upToken的Url，**强烈建议设置**（服务端提供）</span>
                            <span class="comment">// uptoken : '<your upload="" token="">', //若未指定uptoken_url,则必须指定 uptoken ,uptoken由其他程序生成</your></span><your
                                        upload="" token="">
                            <span class="comment">// unique_names: false, // 默认 false，key为文件名。若开启该选项，SDK为自动生成上传成功后的key（文件名）。</span>
                            <span class="comment">// save_key: false,   // 默认 false。若在服务端生成uptoken的上传策略中指定了 `sava_key`，则开启，SDK会忽略对key的处理</span>
                            domain: <span class="string">'http://qiniu-plupload.qiniudn.com/'</span>,   <span
                                            class="comment">//bucket 域名，下载资源时用到，**必需**</span>
                            get_new_uptoken: <span class="literal">false</span>,  <span class="comment">//设置上传文件的时候是否每次都重新获取新的token</span>
                            container: <span class="string">'container'</span>,           <span class="comment">//上传区域DOM ID，默认是browser_button的父元素，</span>
                            max_file_size: <span class="string">'100mb'</span>,           <span class="comment">//最大文件体积限制</span>
                            flash_swf_url: <span class="string">'js/plupload/Moxie.swf'</span>,  <span class="comment">//引入flash,相对路径</span>
                            max_retries: <span class="number">3</span>,                   <span class="comment">//上传失败最大重试次数</span>
                            dragdrop: <span class="literal">true</span>,                   <span class="comment">//开启可拖曳上传</span>
                            drop_element: <span class="string">'container'</span>,        <span class="comment">//拖曳上传区域元素的ID，拖曳文件或文件夹后可触发上传</span>
                            chunk_size: <span class="string">'4mb'</span>,                <span class="comment">//分块上传时，每片的体积</span>
                            auto_start: <span class="literal">true</span>,                 <span class="comment">//选择文件后自动上传，若关闭需要自己绑定事件触发上传</span>
                            init: {
                                <span class="string">'FilesAdded'</span>: <span class="keyword">function</span>(up, files) {
                                    plupload.each(files, <span class="keyword">function</span>(file) {
                                        <span class="comment">// 文件添加进队列后,处理相关的事情</span>
                                    });
                                },
                                <span class="string">'BeforeUpload'</span>: <span class="keyword">function</span>(up, file) {
                                       <span class="comment">// 每个文件上传前,处理相关的事情</span>
                                },
                                <span class="string">'UploadProgress'</span>: <span class="keyword">function</span>(up, file) {
                                       <span class="comment">// 每个文件上传时,处理相关的事情</span>
                                },
                                <span class="string">'FileUploaded'</span>: <span class="keyword">function</span>(up, file, info) {
                                       <span class="comment">// 每个文件上传成功后,处理相关的事情</span>
                                       <span class="comment">// 其中 info 是文件上传成功后，服务端返回的json，形式如</span>
                                       <span class="comment">// {</span>
                                       <span class="comment">//    "hash": "Fh8xVqod2MQ1mocfI4S4KpRL6D98",</span>
                                       <span class="comment">//    "key": "gogopher.jpg"</span>
                                       <span class="comment">//  }</span>
                                       <span class="comment">// 参考http://developer.qiniu.com/docs/v6/api/overview/up/response/simple-response.html</span>

                                       <span class="comment">// var domain = up.getOption('domain');</span>
                                       <span class="comment">// var res = parseJSON(info);</span>
                                       <span class="comment">// var sourceLink = domain + res.key; 获取上传成功后的文件的Url</span>
                                },
                                <span class="string">'Error'</span>: <span class="keyword">function</span>(up, err, errTip) {
                                       <span class="comment">//上传出错时,处理相关的事情</span>
                                },
                                <span class="string">'UploadComplete'</span>: <span class="keyword">function</span>() {
                                       <span class="comment">//队列文件处理完毕后,处理相关的事情</span>
                                },
                                <span class="string">'Key'</span>: <span class="keyword">function</span>(up, file) {
                                    <span class="comment">// 若想在前端对每个文件的key进行个性化处理，可以配置该函数</span>
                                    <span class="comment">// 该配置必须要在 unique_names: false , save_key: false 时才生效</span>

                                    <span class="keyword">var</span> key = <span class="string">""</span>;
                                    <span class="comment">// do something with key here</span>
                                    <span class="keyword">return</span> key
                                }
                            }
                        });


                        </your></code></pre>
                        </div>
                    </div>

                </div>
                <div role="tabpanel" class="tab-pane fade" id="log" aria-labelledby="log-tab">
                    <pre id="qiniu-js-sdk-log"><p>[qiniu-js-sdk][debug] init uploader start</p><p>[qiniu-js-sdk][debug] environment:  {"browser":"Chrome","version":50,"os":"Mac OS X","osVersion":"10.10.5","swf_url":"../flash/Moxie.swf","xap_url":"../silverlight/Moxie.xap","global_event_dispatcher":"moxie.core.EventTarget.instance.dispatchEvent","OS":"Mac OS X"}</p><p>[qiniu-js-sdk][debug] userAgent:  Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36</p><p>[qiniu-js-sdk][debug] invoke reset_chunk_size()</p><p>[qiniu-js-sdk][debug] op.chunk_size:  4mb</p><p>[qiniu-js-sdk][debug] option:  {"runtimes":"html5,flash,html4","browse_button":"pickfiles","container":"container","drop_element":"container","max_file_size":"1000mb","flash_swf_url":"bower_components/plupload/js/Moxie.swf","dragdrop":true,"chunk_size":"4mb","multi_selection":true,"uptoken_url":"uptoken","domain":"http://7xocov.com2.z0.glb.qiniucdn.com/","get_new_uptoken":false,"auto_start":true,"log_level":5,"init":{},"url":"http://upload.qiniu.com","multipart_params":{"token":""}}</p><p>[qiniu-js-sdk][debug] new plupload.Uploader(option)</p><p>[qiniu-js-sdk][debug] bind Init event</p><p>[qiniu-js-sdk][debug] bind FilesAdded event</p><p>[qiniu-js-sdk][debug] bind BeforeUpload event</p><p>[qiniu-js-sdk][debug] bind UploadProgress event</p><p>[qiniu-js-sdk][debug] bind ChunkUploaded event</p><p>[qiniu-js-sdk][debug] bind Error event</p><p>[qiniu-js-sdk][debug] bind FileUploaded event</p><p>[qiniu-js-sdk][debug] invoke uploader.init()</p><p>[qiniu-js-sdk][debug] init uploader end</p><p>[qiniu-js-sdk][debug] Init event activated</p><p>[qiniu-js-sdk][debug] get uptoken from:  uptoken</p><p>[qiniu-js-sdk][debug] get new uptoken:  JOiPUijNB0t8vbNKIufpn5gDKmg0G-uFHBlrQoV2:fAZ9PIhVnJ4hLNvGRQClLf9Bppg=:eyJzY29wZSI6Impzc2RrIiwiZGVhZGxpbmUiOjE0NjM2NDM2NDZ9</p></pre>
                </div>
            </div>
        </div>
    </#if>

</form>
<div class="col-xs-2" style="text-align: center;width: 100%;margin-top: 40px">
    <button class="btn btn-success" id="save_btn">保存</button>
</div>
<#if  upToken??>
    <script type="text/javascript" src="/qiniu/jquery.min.js"></script>
    <script type="text/javascript" src="/qiniu/bootstrap.min.js"></script>
    <script type="text/javascript" src="/qiniu/moxie.js"></script>
    <script type="text/javascript" src="/qiniu/plupload.dev.js"></script>
    <!-- <script type="text/javascript" src="bower_components/plupload/js/plupload.full.min.js"></script> -->
    <script type="text/javascript" src="/qiniu/zh_CN.js"></script>
    <script type="text/javascript" src="/qiniu/ui.js"></script>
    <script type="text/javascript" src="/qiniu/qiniu.js"></script>
    <script type="text/javascript" src="/qiniu/highlight.js"></script>
    <script type="text/javascript" src="/qiniu/main.js"></script>
    <script type="text/javascript">hljs.initHighlightingOnLoad();</script>
</#if>
<script>
    $(document).on("click", "#container", function () {
        if (!$("#appStore").val()) {
            alert("请选择应用渠道！");
            return false;
        }
        if (!$("#innerCode").val()) {
            alert("请填入内置版本！");
            return false;
        }
    })
    $(document).ready(function () {

        $("#save_btn").click(function () {
            if (!$("#appId").val()) {
                alert("请填入应用名称！");
                return false;
            }
            if (!$("#content").val()) {
                alert("请填入更新内容！");
                return false;
            }
            if (!$("#subtitle").val()) {
                alert("请填入应用描述！");
                return false;
            }
            if (!$("#version").val()) {
                alert("请填入外网版本！");
                return false;
            }
            if (!$("#innerCode").val()) {
                alert("请填入内置版本！");
                return false;
            }
            if (!$("#title").val()) {
                alert("请填入标题！");
                return false;
            }
            if (!$("#appMode").val()) {
                alert("请选择版本模式！");
                return false;
            }
            if(!$("#openBlackPkg").val()){
                alert("请选择是否开启违禁包检测！");
                return false;
            }

            var formData = new FormData();
            var appId = $('#appId').val();
            var id = $('#id').val();
            var appStore = $('#appStore').val();
            var title = $('#title').val();
            var subtitle = $('#subtitle').val();
            var content = $('#content').val();
            var version = $('#version').val();
            var innerCode = $('#innerCode').val();
            var appMode = $('#appMode').val();
            var tipUser = $('#tipUser').val();
            var forceUpdate = $('#forceUpdate').val();
            var sameVersionUpdate = $('#sameVersionUpdate').val();
            var href = $('#href').val();
            var openBlackPkg = $('#openBlackPkg').val();
            formData.append("id", id);
            formData.append("appId", appId);
            formData.append("appStore", appStore);
            formData.append("title", title);
            formData.append("subtitle", subtitle);
            formData.append("content", content);
            formData.append("version", version);
            formData.append("innerCode", innerCode);
            formData.append("appMode", appMode);
            formData.append("tipUser", tipUser);
            formData.append("forceUpdate", forceUpdate);
            formData.append("sameVersionUpdate", sameVersionUpdate);
            formData.append("href", href);
            formData.append("openBlackPkg",openBlackPkg);
            $.ajax({
                type: "post",
                url: "/apps/save",
                data: formData,
                async: false,
                cache: false,
                contentType: false, //不设置内容类型
                processData: false, //不处理数据
                success: function (res) {
                    alert('修改成功');
                    window.parent.iw.closeDialog();
                }
            });
        });
    });
</script>
</body>
</html>
